<?php
/**
 * return js scripts
 *
 * @todo minimize/compress/encode
 *
 * @author kim
 */
class App_View_Helper_Js extends Zend_View_Helper_Abstract
{
    static $i = 0;

    /**
     * @return object
     */
    public function js($file = false, $index = false)
    {
        if ($file and file_exists(APPLICATION_PATH . '/../public/js/' . $file)) {
            if ($index) {
                $this->view->headScript()->offsetSetFile(intval($index), WEB_URL . '/js/' . $file);
            } else {
                $this->view->headScript()->offsetSetFile(self::$i++, WEB_URL . '/js/' . $file);
            }
        }
        return $this;
    }

    /**
     * @return string
     */
    public function __toString()
    {
        return $this->view->headScript()->toString();
    }

}
